# -*- encoding:utf8 -*-

from celery import shared_task
from freeze import zip_studio
from celery.task.control import revoke
from django.conf import settings
from app_info import update_studio_appset
from deploy import auto_deploy,deploy_studio
# import redis
# host='localhost', port=6379, db=0

# r = redis.StrictRedis(**settings.REDIS)

@shared_task
def myadd(x, y):
    rt = x *y
    print(rt)
    return rt


def freeze_studio_with_celery(studio):
    if r.get(studio.name):
        revoke(r.get(studio.name), terminate=True)   
    rt = freeze_studio.delay(studio)
    r.set(studio.name,rt.id)
 
@shared_task
def freeze_studio(studio):
    zip_studio(studio)


@shared_task
def update_studio_appset_with_celery(name):
    update_studio_appset(name)
    

@shared_task
def auto_deploy_with_celery():
    auto_deploy()


@shared_task
def deploy_studio_with_celery(studio):
    """
    @sutdio: model object
    """
    deploy_studio(studio)

# @shared_task
# def update_app_with_celery(sku,studio_name):
    # update_app(sku, studio_name)


